package logic

import (
	"context"
	"gorm.io/gorm"
	"sport/models/mysql"
	"sport/sportrpc/internal/svc"
	"sport/sportrpc/sportrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAddLogic {
	return &UserAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 完善信息
func (l *UserAddLogic) UserAdd(in *sportrpc.UserAddRequest) (*sportrpc.UserAddResponse, error) {
	// todo: add your logic here and delete this line
	users := mysql.User{
		Model:   gorm.Model{ID: uint(in.UserId)},
		Name:    in.Name,
		Image:   in.Image,
		Address: in.Address,
	}
	mysql.DB.Updates(&users)
	return &sportrpc.UserAddResponse{
		Id: int64(users.ID),
	}, nil
}
